﻿using System;
using System.Runtime.Serialization;
using Eflong.MonitoringLib.MonitoringUnit;

using Modalities = Eflong.MonitoringLib.MonitoringUnit.MonitoringUnitModality.Modalities;
using States = Eflong.MonitoringLib.MonitoringUnit.MonitoringUnitState.States;

namespace Eflong.DTO.Wcf
{
    [DataContract]
    public class InterlockedBreaker : IDisposable
    {
        public void Dispose( )
        {
        }

        //Id        -1
        [DataMember]
        public int Id { get; set; }

        /// <summary>
        /// 矿井编号 -2
        /// </summary>
        [DataMember]
        public int CoalMineId { get; set; }

        /// <summary>
        /// 煤矿名称 -3
        /// </summary>
        [DataMember]
        public string CoalMineName { get; set; }

        /// <summary>
        /// 闭锁名称     -4
        /// </summary>
        [DataMember]
        public string Name { get; set; }

        /// <summary>
        /// 地点         -5
        /// </summary>
        [DataMember]
        public string Location { get; set; }

        /// <summary>
        /// 闭锁类型     -6
        /// </summary>
        [DataMember]
        public string Type { get; set; }

        /// <summary>
        /// 延迟时间     -7
        /// </summary>
        [DataMember]
        public float Delaytime { get; set; }

        // 甲烷传感器Id 1   -8
        [DataMember]
        public string MethaneSensorId { get; set; }

        // 甲烷传感器Id 2   -9
        [DataMember]
        public string MethaneSensorId2 { get; set; }

        // 风机1            -10
        [DataMember]
        public string FanSensorId { get; set; }

        // 风机2            -11
        [DataMember]
        public string FanSensorId2 { get; set; }

        // 风机1-2            -10
        [DataMember]
        public string FanSensorId_2 { get; set; }

        // 风机2-2            -11
        [DataMember]
        public string FanSensorId2_2 { get; set; }

        // 闭锁             -12
        [DataMember]
        public string LockedSensorId { get; set; }

        // 断电器           -13
        [DataMember]
        public string BreakerSensorId { get; set; }

        // 馈电器           -14
        [DataMember]
        public string FeedSensorId { get; set; }

        // 断电器 2         -15
        [DataMember]
        public string BreakerSensorId2 { get; set; }

        // 馈电器 2         -16
        [DataMember]
        public string FeedSensorId2 { get; set; }

        /// <summary>
        /// 甲烷传感器数值   -17
        /// </summary>
        [DataMember]
        public string MethaneSensorValue { get; set; }

        // 甲烷传感器2 数值

        [DataMember]
        public string MethaneSensorValue2 { get; set; }

        // 风机1 状态

        [DataMember]
        public string FanSensorValue { get; set; }

        // 风机2 状态
        [DataMember]
        public string FanSensorValue2 { get; set; }

        // 断电器状态

        [DataMember]
        public string BreakerSensorValue { get; set; }

        // 馈电器状态

        [DataMember]
        public string FeedSensorValue { get; set; }

        // 闭锁状态

        [DataMember]
        public string LockedSensorValue { get; set; }

        // 断电器2 状态
        [DataMember]
        public string BreakerSensorValue2 { get; set; }

        // 馈电器2 状态

        [DataMember]
        public string FeedSensorValue2 { get; set; }

        // 是否闭锁
        public bool IsLocked { get; set; }

        // 开始时刻
        [DataMember]
        public DateTime BeginTime { get; set; }

        // 结束时刻
        [DataMember]
        public DateTime EndTime { get; set; }

        // 原因
        [DataMember]
        public string Causation { get; set; }

        // 采取措施
        [DataMember]
        public string Measure { get; set; }

        // 采取措施时刻
        [DataMember]
        public DateTime MeasureTime { get; set; }

        // 是否馈电异常
        [DataMember]
        public bool IsFeedAbnormal { get; set; }

        //
        public bool Update { get; set; }

        public DateTime UpdateTime { get; set; }

        // 确认
        public bool Valid { get; set; }

        // 确认时刻
        public DateTime ValidTime { get; set; }

        public InterlockedBreaker Clone( )
        {
            return this.MemberwiseClone( ) as InterlockedBreaker;
        }
    }

    /// <summary>
    /// 联网矿的状态
    /// </summary>
    public enum ConnectStates { 状态未知 = 0 , UnKnownState = 0 , 正常 = 1 , NormalState = 1 , 报警 = 2 , AlertState = 2 , 通信故障 = 3 , FaultState = 3 , 数据不变化 = 4 , NoChangedState = 4 , 网络中断 = 5 , };

    [DataContract]
    public class NetStatus : IDisposable
    {
        public NetStatus( )
        {
        }

        public void Dispose( )
        {
        }

        [DataMember]
        public int CoalMineId { get; set; }

        [DataMember]
        public string CoalMineName { get; set; }

        [DataMember]
        public string IPAddr { get; set; }

        [DataMember]
        public DateTime BeginTime { get; set; }

        public DateTime EndTime { get; set; }

        [DataMember]
        public string Causation { get; set; }

        [DataMember]
        public string Measure { get; set; }

        public DateTime MeasureTime { get; set; }

        [DataMember]
        public uint State { get; set; }

        public string Note { get; set; }

        public bool Update { get; set; }

        public DateTime UpdateTime { get; set; }

        /// <summary>
        /// 获取联网状态字符串
        /// </summary>
        /// <returns></returns>
        public String GetConnectStateString( )
        {
            string StateString = string.Empty;
            switch ( State )
            {
                case ( int )ConnectStates.FaultState:
                    StateString = "网络中断";
                    break;

                case ( int )ConnectStates.NoChangedState:
                    StateString = "数据不变化";
                    break;

                case ( int )ConnectStates.UnKnownState:
                    StateString = "未知";
                    break;

                case ( int )ConnectStates.NormalState:
                    StateString = "正常";
                    break;

                case ( int )ConnectStates.AlertState:
                    StateString = "报警";
                    break;
                default:
                    StateString = "未知";
                    break;
            }
            return StateString;
        }
    }

    [DataContract]
    public class EarlyWarning : IDisposable
    {
        public EarlyWarning( )
        {
        }

        public void Dispose( )
        {
        }

        //Id
        [DataMember]
        public int Id { get; set; }

        // 矿井编号
        [DataMember]
        public int CoalMineId { get; set; }

        //
        [DataMember]
        public string CoalMineName { get; set; }

        // 预警名称
        [DataMember]
        public string Name { get; set; }

        // 预警地点
        [DataMember]
        public string Location { get; set; }

        // 预警类型
        [DataMember]
        public string Type { get; set; }

        // 延迟时间
        public float Delaytime { get; set; }

        // 地点类别
        [DataMember]
        public string AddrType { get; set; }

        // 传感器Id
        [DataMember]
        public string SensorId { get; set; }

        // 预警值

        [DataMember]
        public float WarnValue { get; set; }

        // 预警低值

        [DataMember]
        public float WarnLowValue { get; set; }

        // 预警高值

        [DataMember]
        public float WarnHightValue { get; set; }

        // 预警时长
        [DataMember]
        public float WarnTime { get; set; }

        // 关联风量
        [DataMember]
        public float BlastVolume { get; set; }

        // 关联测点
        [DataMember]
        public string LinkedSensorId { get; set; }

        // 预测值

        [DataMember]
        public string CurrValue { get; set; }

        // 是否预警
        [DataMember]
        public bool IsWarnning { get; set; }

        // 开始时刻

        [DataMember]
        public DateTime BeginTime { get; set; }

        // 结束时刻
        [DataMember]
        public DateTime EndTime { get; set; }

        // 原因
        [DataMember]
        public string Causation { get; set; }

        // 采取措施
        [DataMember]
        public string Measure { get; set; }

        // 采取措施时刻
        [DataMember]
        public DateTime MeasureTime { get; set; }

        //
        public bool Update { get; set; }

        public DateTime UpdateTime { get; set; }

        // 确认
        public bool Valid { get; set; }

        // 确认时刻
        public DateTime ValidTime { get; set; }

        public EarlyWarning Clone( )
        {
            return this.MemberwiseClone( ) as EarlyWarning;
        }
    }

    [DataContract]

    /// <summary>
    ///  传感器报警信息

    /// </summary>
    public class SensorAlert : IDisposable
    {
        public SensorAlert( )
        {
        }

        public void Dispose( )
        {
        }

        /// <summary>
        /// 传感器唯一标志
        /// 例如：3-01A01
        /// </summary>
        public string symbol { get; set; }

        /// <summary>
        /// 矿的ID
        /// </summary>
        [DataMember]
        public long CoalMineId { get; set; }

        /// <summary>
        /// 矿名称

        /// </summary>
        [DataMember]
        public string CoalMineName { get; set; }

        /// <summary>
        /// 传感器的 ID
        /// </summary>
        [DataMember]
        public string MonUnitId { get; set; }

        /// <summary>
        /// 名称及地点信息

        /// </summary>
        [DataMember]
        public string Name { get; set; }

        /// <summary>
        /// 传感器分类

        /// 1:模拟量 2：开关量 3：累计量
        /// </summary>
        [DataMember]
        public Modalities Modality { get; set; }

        /// <summary>
        /// 传感器类型
        ///甲烷、一氧化碳、风速
        ///风机、风门、主扇、局扇
        /// </summary>
        [DataMember]
        public MonitoringUnitType.Types Type { get; set; }

        /// <summary>
        /// 传感器类型名
        /// </summary>
        [DataMember]
        public string sType { get; set; }

        /// <summary>
        /// 传感器单位
        /// </summary>
        [DataMember]
        public string Unit { get; set; }

        /// <summary>
        /// 报警下限
        /// </summary>
        [DataMember]
        public float LowerLimit { get; set; }

        /// <summary>
        /// 报警上限
        /// </summary>
        [DataMember]
        public float UpperLimit { get; set; }

        /// <summary>
        /// 断电门限
        /// </summary>
        [DataMember]
        public float PowerOffLimit { get; set; }

        /// <summary>
        /// 复电门限
        /// </summary>
        [DataMember]
        public float PowerOnLimit { get; set; }

        /// <summary>
        /// 当前值

        /// </summary>
        [DataMember]
        public float Value { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        [DataMember]
        public States State { get; set; }

        /// <summary>
        /// 文字描述
        /// </summary>
        [DataMember]
        public string[ ] ValueDecs = new string[ 3 ];

        /// <summary>
        /// 状态改变时刻
        /// </summary>
        [DataMember]
        public DateTime StateChangeTime { get; set; }

        /// <summary>
        /// 数据改变时刻
        /// </summary>
        [DataMember]
        public DateTime DataChangeTime { get; set; }

        /// <summary>
        /// 报警值
        /// </summary>
        [DataMember]
        public float AlertValue { get; set; }

        /// <summary>
        /// 断电值
        /// </summary>
        [DataMember]
        public float BreakValue { get; set; }

        /// <summary>
        /// 复电值
        /// </summary>
        [DataMember]
        public float RestValue { get; set; }

        /// <summary>
        /// 是否正在报警
        /// </summary>
        public bool IsAlert;

        /// <summary>
        /// 是否正在断电
        /// </summary>
        public bool IsBreak;

        /// <summary>
        /// 是否复电
        /// </summary>
        public bool IsRest;

        /// <summary>
        /// 是否故障
        /// </summary>
        public bool IsFault;

        /// <summary>
        /// 是否已经解除
        /// </summary>
        public bool IsFinish;

        /// <summary>
        /// 是否写入当前报警记录
        /// </summary>
        public bool IsRecord;

        /// <summary>
        /// 需要写入到当前表的记录
        /// </summary>
        public bool IsNeedRecord;

        /// <summary>
        /// 是否更新
        /// </summary>
        public bool IsUpdate;

        /// <summary>
        /// 需要更新记录吗
        /// </summary>
        public bool IsNeedUpdate { get; set; }

        /// <summary>
        /// 更新时刻
        /// </summary>
        public DateTime tmUpdate { get; set; }

        /// <summary>
        /// 开始时刻

        /// </summary>
        [DataMember]
        public DateTime tmStart { get; set; }

        /// <summary>
        /// 解除时刻
        /// </summary>
        [DataMember]
        public DateTime tmStop { get; set; }

        /// <summary>
        /// 报警原因
        /// </summary>
        [DataMember]
        public string Causation { get; set; }

        /// <summary>
        /// 采取措施
        /// </summary>
        [DataMember]
        public string AdoptMeasure { get; set; }

        /// <summary>
        /// 采取措施时刻
        /// </summary>
        [DataMember]
        public DateTime AdoptMeasureTime { get; set; }

        /// <summary>
        /// 原因分析
        /// </summary>
        [DataMember]
        public string AnalyseInfo { get; set; }

        /// <summary>
        /// 传感器报警值
        /// </summary>
        [DataMember]
        public float fAlertValue { get; set; }

        /// <summary>
        /// 传感器解除值
        /// </summary>
        [DataMember]
        public float fRelievedValue { get; set; }

        /// <summary>
        /// 报警、解除状态
        /// </summary>
        [DataMember]
        public string sValue { get; set; }

        /// <summary>
        /// 报警最大值

        /// </summary>
        [DataMember]
        public float fMaxValue { get; set; }

        /// <summary>
        /// 报警最大时刻
        /// </summary>
        [DataMember]
        public DateTime tmMaxValue { get; set; }

        /// <summary>
        /// 报警最小值

        /// </summary>
        [DataMember]
        public float fMinValue { get; set; }

        /// <summary>
        /// 报警最小时刻
        /// </summary>
        [DataMember]
        public DateTime tmMinValue { get; set; }

        /// <summary>
        ///  平均值

        /// </summary>
        [DataMember]
        public float fAvgValue { get; set; }

        // sum
        private float fSumValue;

        // sum count
        private float fSumCount;

        /// <summary>
        ///  报警次数
        /// </summary>
        [DataMember]
        public Int32 nAlertCount { get; set; }

        /// <summary>
        /// 报警时长
        /// </summary>
        [DataMember]
        public float fAlertTime { get; set; }
    }

    [DataContract]
    public class SensorFault : IDisposable
    {
        public SensorFault( )
        {
        }

        public void Dispose( )
        {
        }

        /// <summary>
        /// 传感器唯一标志
        /// 例如：3-01A01
        /// </summary>
        [DataMember]
        public string symbol { get; set; }

        /// <summary>
        /// 矿的ID
        /// </summary>
        [DataMember]
        public long CoalMineId { get; set; }

        /// <summary>
        /// 矿名称

        /// </summary>
        [DataMember]
        public string CoalMineName { get; set; }

        /// <summary>
        /// 传感器的 ID
        /// </summary>
        [DataMember]
        public string MonUnitId { get; set; }

        /// <summary>
        /// 名称及地点信息

        /// </summary>
        [DataMember]
        public string Name { get; set; }

        /// <summary>
        /// 传感器分类
        /// 1:模拟量 2：开关量 3：累计量
        /// </summary>
        [DataMember]
        public Modalities Modality { get; set; }

        /// <summary>
        /// 传感器类型
        ///甲烷、一氧化碳、风速
        ///风机、风门、主扇、局扇
        /// </summary>
        [DataMember]
        public MonitoringUnitType.Types nType { get; set; }

        /// <summary>
        /// 传感器类型名
        /// </summary>
        [DataMember]
        public string sType { get; set; }

        /// <summary>
        /// 传感器单位
        /// </summary>
        [DataMember]
        public string sUnit { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        [DataMember]
        public States State { get; set; }

        // 故障次数
        [DataMember]
        public Int32 nFaultCount { get; set; }

        // 故障时长
        [DataMember]
        public float fFaultTime { get; set; }

        /// <summary>
        /// 开始时刻
        /// </summary>
        [DataMember]
        public DateTime tmStart { get; set; }

        /// <summary>
        /// 解除时刻
        /// </summary>
        [DataMember]
        public DateTime tmStop { get; set; }

        /// <summary>
        /// 报警原因
        /// </summary>
        [DataMember]
        public string Causation { get; set; }

        /// <summary>
        /// 采取措施
        /// </summary>
        [DataMember]
        public string AdoptMeasure { get; set; }

        /// <summary>
        /// 采取措施时刻
        /// </summary>
        [DataMember]
        public DateTime AdoptMeasureTime { get; set; }

        /// <summary>
        /// 原因分析
        /// </summary>
        [DataMember]
        public string AnalyseInfo { get; set; }
    }

    public enum ModifyFlags { None = 0 , 新增 = 1 , 修改 = 2 , 删除 = 3 };

    [DataContract]
    public class MonitoringUnit : IDisposable
    {
        public MonitoringUnit( ) { }

        public void Dispose( )
        {
        }

        public MonitoringUnit Clone( )
        {
            MonitoringUnit u = ( MonitoringUnit )this.MemberwiseClone( );
            return u;
        }

        /// <summary>
        /// 测点号

        /// </summary>
        [DataMember]
        public string m_strId { get; set; }

        /// <summary>
        /// 唯一标识
        /// </summary>
        [DataMember]
        public string symbol { get; set; }

        /// <summary>
        /// 测点后缀
        /// </summary>
        [DataMember]
        public string m_strPostfix { get; set; }

        /// <summary>
        /// 系统编号，系统1 或 系统2
        /// </summary>
        [DataMember]
        public int nSysNo { get; set; }

        /// <summary>
        /// 测点名称
        /// </summary>
        [DataMember]
        public string m_strName { get; set; }

        /// <summary>
        /// 测点分类
        /// </summary>
        [DataMember]

        //public MonitoringUnitModality.Modalities m_Modality { get; set; }
        public int m_Modality { get; set; }

        /// <summary>
        /// 传感器类型

        /// </summary>
        //public MonitoringUnitType.Types m_Type { get; set; }
        public int m_Type { get; set; }

        /// <summary>
        /// 数据变化时刻
        /// </summary>
        [DataMember]
        public DateTime m_timeData { get; set; }

        /// <summary>
        /// 状态改变时刻

        /// </summary>
        public DateTime m_timeStateChange { get; set; }

        /// <summary>
        /// 状态

        /// </summary>
        [DataMember]

        //public MonitoringUnitState.States m_State { get; set; }
        public int m_State { get; set; }

        /// <summary>
        /// 实时数据
        /// </summary>
        [DataMember]
        public float m_fValue { get; set; }

        /// <summary>
        /// 模拟量状态

        /// </summary>
        //[DataMember]
        //public MonitoringUnitState.AnalogStates m_AnalogState { get; set; }
        //public int m_AnalogState { get; set; }

        /// <summary>
        /// 开关量状态

        /// </summary>
        //[DataMember]
        //public MonitoringUnitState.DigitalStates m_DigitalState { get; set; }
        //public int m_DigitalState { get; set; }
        /// <summary>
        /// 是否报警
        /// </summary>
        [DataMember]
        public bool IsAlert { get; set; }

        /// <summary>
        /// 是否断电
        /// </summary>
        [DataMember]
        public bool IsBreak { get; set; }

        /// <summary>
        /// 是否复电
        /// </summary>
        [DataMember]
        public bool IsRest { get; set; }

        /// <summary>
        /// 是否故障
        /// </summary>
        [DataMember]
        public bool IsFault { get; set; }

        /// <summary>
        /// 是否馈电
        /// </summary>
        [DataMember]
        public bool IsFeed { get; set; }

        /// <summary>
        /// 是否馈电异常
        /// </summary>
        [DataMember]
        public bool IsFeedAbnormal { get; set; }

        /// <summary>
        /// 报警时刻
        /// </summary>
        [DataMember]
        public DateTime tmAlert { get; set; }

        /// <summary>
        /// 断电时刻
        /// </summary>
        [DataMember]
        public DateTime tmBreak { get; set; }

        /// <summary>
        /// 复电时刻
        /// </summary>
        [DataMember]
        public DateTime tmRest { get; set; }

        /// <summary>
        /// 故障时刻
        /// </summary>
        [DataMember]
        public DateTime tmFault { get; set; }

        /// <summary>
        /// 馈电时刻
        /// </summary>
        [DataMember]
        public DateTime tmFeed { get; set; }

        /// <summary>
        /// 馈电异常时刻
        /// </summary>
        [DataMember]
        public DateTime tmFeedAbnormal { get; set; }

        /// <summary>
        /// 单位
        /// </summary>
        [DataMember]
        public string m_strUnit { get; set; }

        [DataMember]
        public float m_fLowerBound { get; set; }

        [DataMember]
        public float m_fUpperBound { get; set; }

        [DataMember]
        public float m_fLowerLimit { get; set; }

        [DataMember]
        public float m_fUpperLimit { get; set; }

        /// <summary>
        /// 断电门限
        /// </summary>
        [DataMember]
        public float m_fBreakLimit { get; set; }

        /// <summary>
        /// 复电门限
        /// </summary>
        [DataMember]
        public float m_fRestLimit { get; set; }

        /// <summary>
        /// 记录变化区域单位
        /// </summary>
        [DataMember]
        public byte m_byRecChangeAmp { get; set; }

        [DataMember]
        public bool m_bTriState { get; set; }

        [DataMember]
        public string[ ] m_strStateName { get; set; }

        /// <summary>
        /// (16)、关联传感器编号：与此传感器有关联的传感器编号，如有多个关联传感器编号之间用分号分割。
        /// 例如：传感器1-5的关联传感器为d1-1;k1-3;b1-4
        /// 说明：1-5传感器的断电器为1-1，馈电器为1-3，闭锁传感器为1-4
        /// </summary>
        [DataMember]
        public string LinkageNO { get; set; }

        /// <summary>
        /// 馈电器为1-3
        /// </summary>
        [DataMember]
        public string KDSensorID { get; set; }

        /// <summary>
        /// 断电器为1-1
        /// </summary>
        [DataMember]
        public string DDSensorID { get; set; }

        /// <summary>
        /// 闭锁传感器为1-4
        /// </summary>
        [DataMember]
        public string BSSensorID { get; set; }
    }
}